package com.fan.admin.config;


import com.fan.commons.pojo.ClaInfo;
import com.fan.commons.pojo.CollegeInfo;
import com.fan.commons.pojo.SystemInfo;
import com.fan.commons.pojo.Teacher;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * @author fan
 * @date 2021/1/25
 */
@Slf4j
@Data
@Component
public class InitConfig {

	private HashMap<String, CollegeInfo> collegeMap = new HashMap<>();
	private HashMap<String, SystemInfo> systemMap = new HashMap<>();
	private HashMap<String, ClaInfo> claPojoMap = new HashMap<>();
	private List<Teacher> teacherList = new ArrayList<>();


	public HashMap<String, CollegeInfo> getCollegeMap() {
		return collegeMap;
	}

	public HashMap<String, SystemInfo> getSystemMap() {
		return systemMap;
	}

	public HashMap<String, ClaInfo> getClaPojoMap() {
		return claPojoMap;
	}

	public List<Teacher> getTeacherList() {
		return teacherList;
	}

	public void initInfo() {
		initCollegeInfo();
		log.info("initCollegeInfo success!");
		initSystemInfo();
		log.info("initSystemInfo success!");
		initCalPojoInfo();
		log.info("initCalPojoInfo success!");
		initTeacherInfo();
		log.info("initTeacherInfo success!");
	}

	private void initCollegeInfo() {
		CollegeInfo collegeInfo = new CollegeInfo(1, "c001", "软件学院");
		collegeMap.put(collegeInfo.getCollegeId(), collegeInfo);

		collegeInfo = new CollegeInfo(2, "c002", "信工学院");
		collegeMap.put(collegeInfo.getCollegeId(), collegeInfo);

		collegeInfo = new CollegeInfo(4, "c003", "理学院");
		collegeMap.put(collegeInfo.getCollegeId(), collegeInfo);
	}

	private void initSystemInfo() {
		SystemInfo systemInfo = new SystemInfo(1, "s001", "c001", "软件工程");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
		systemInfo = new SystemInfo(2, "s002", "c001", "网络工程");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
		systemInfo = new SystemInfo(3, "s003", "c002", "网络空间安全");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
		systemInfo = new SystemInfo(4, "s004", "c002", "通信工程");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
		systemInfo = new SystemInfo(5, "s005", "c003", "数学类");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
		systemInfo = new SystemInfo(6, "s006", "c003", "统计学");
		systemMap.put(systemInfo.getSystemId(), systemInfo);
	}

	private void initCalPojoInfo() {
		ClaInfo claInfo = new ClaInfo(1, "17213", "s001");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(2, "17214", "s001");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(3, "17215", "s002");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(4, "17216", "s002");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(5, "17217", "s003");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(6, "17218", "s003");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(7, "17219", "s004");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(8, "17219", "s004");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(9, "17201", "s005");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(10, "17208", "s005");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(11, "17209", "s006");
		claPojoMap.put(claInfo.getClaId(), claInfo);
		claInfo = new ClaInfo(12, "17202", "s006");
		claPojoMap.put(claInfo.getClaId(), claInfo);
	}

	public void initTeacherInfo() {
		HashMap<String, SystemInfo> systemMap = this.getSystemMap();
		Teacher teacher;
		String name;
		int id = 0;
		for (SystemInfo value : systemMap.values()) {
			for (int i = 1000; i < 1010; i++) {
				teacher = new Teacher();
				teacher.setId(++id);
				teacher.setTeacherId(value.getCollegeId() + value.getSystemId() + i);
				name = UUID.randomUUID().toString().substring(25, 36);
				teacher.setName(name);
				teacher.setGender(i % 2);
				teacher.setPassword("123456");
				teacher.setEmail(name + "@edu.com");
				teacher.setPhone("01234567890");
				teacher.setCollegeId(value.getCollegeId());
				teacher.setSystemId(value.getSystemId());
				teacher.setRole(2);
				teacherList.add(teacher);
			}
		}
	}
}
